﻿Imports System.Windows.Media.Animation
Imports System.Windows.Threading
Imports Hinshelwood.TFSStickyBuddy.Modules.Interfaces

Namespace Views


    Partial Public Class CredentialProviderView
        Implements ICredentialProviderView

        Private Sub NotImplementedPopup_IsVisibleChanged(ByVal sender As Object, ByVal e As System.Windows.DependencyPropertyChangedEventArgs) Handles Me.IsVisibleChanged
            '' Raise the Loaded event so that the intro animation runs.
            If (MyBase.IsVisible) Then
                MyBase.RaiseEvent(New RoutedEventArgs(FrameworkElement.LoadedEvent, Me))
            End If
        End Sub

        Public Property Model() As Interfaces.ICredentialProviderPresentationModel Implements Interfaces.ICredentialProviderView.Model
            Get
                Return Me.DataContext
            End Get
            Set(ByVal value As Interfaces.ICredentialProviderPresentationModel)
                Me.DataContext = value
            End Set
        End Property


        Public Sub CredentialsAuthenticated() Implements Interfaces.ICredentialProviderView.CredentialsAuthenticated
            Me.Visibility = Windows.Visibility.Hidden
        End Sub

        Public Function ShowView(ByVal failedCredentials As System.Net.ICredentials) As Boolean? Implements ICredentialProviderView.ShowView
            Me.Visibility = Windows.Visibility.Visible
        End Function

        Private Sub ux_CancelButton_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
            Me.ux_UsernameTextbox.Text = ""
            Me.ux_PasswordTextbox.Password = ""
        End Sub

        Private Sub ux_OKButton_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
            Dim username As String = Me.ux_UsernameTextbox.Text
            Dim Domain As String = ""
            Dim Password As String = Me.ux_PasswordTextbox.Password
            If Me.ux_UsernameTextbox.Text.IndexOf("\") Then
                Dim split() As String = Me.ux_UsernameTextbox.Text.Split("\")
                Domain = split(0)
                username = split(1)
            Else
                username = Me.ux_UsernameTextbox.Text
            End If
            Model.SelectedCredentials = New System.Net.NetworkCredential(username, Password, Domain)

            ux_OKButton.IsEnabled = False
            ux_CancelButton.IsEnabled = False
        End Sub



    End Class

End Namespace